package com.deyuanyun.pic.pbf.controller.dto.defect;

import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.pbf.domain.DefectStatistics;
import com.deyuanyun.pic.pbf.domain.RepairTask;
import com.deyuanyun.pic.pbf.enumeration.RepairStateEnum;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 缺陷信息统计 数据传输对象
 *
 * @author huanglw
 * @date 2016-7-18
 *
 * History: [修改人][时间][修改描述]
 */
public class DefectStatisticsDto extends DefaultCommand<RepairTask> {

    // 项目名称
    private String repairTaskName;
    // 管道名称
    private String pipeLineName;
    // 管段名称
    private String pipeSegmentName;
    // 建议开工时间
    private String planStartDate;
    // 建议竣工时间
    private String planCompletionDate;
    // 施工单位
    private String assemblyCompany;
    // 缺陷信息统计
    private List<DefectInfoStatistics> defectInfoStatisticsList;
    // 维修状态数量统计
    private List<RepairStateStatistics> repairStateStatisticsList;

    public String getRepairTaskName() {
        return repairTaskName;
    }

    public void setRepairTaskName(String repairTaskName) {
        this.repairTaskName = repairTaskName;
    }

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getPipeSegmentName() {
        return pipeSegmentName;
    }

    public void setPipeSegmentName(String pipeSegmentName) {
        this.pipeSegmentName = pipeSegmentName;
    }

    public String getPlanStartDate() {
        return planStartDate;
    }

    public void setPlanStartDate(String planStartDate) {
        this.planStartDate = planStartDate;
    }

    public String getPlanCompletionDate() {
        return planCompletionDate;
    }

    public void setPlanCompletionDate(String planCompletionDate) {
        this.planCompletionDate = planCompletionDate;
    }

    public String getAssemblyCompany() {
        return assemblyCompany;
    }

    public void setAssemblyCompany(String assemblyCompany) {
        this.assemblyCompany = assemblyCompany;
    }

    public List<DefectInfoStatistics> getDefectInfoStatisticsList() {
        return defectInfoStatisticsList;
    }

    public void setDefectInfoStatisticsList(List<DefectInfoStatistics> defectInfoStatisticsList) {
        this.defectInfoStatisticsList = defectInfoStatisticsList;
    }

    public List<RepairStateStatistics> getRepairStateStatisticsList() {
        return repairStateStatisticsList;
    }

    public void setRepairStateStatisticsList(List<RepairStateStatistics> repairStateStatisticsList) {
        this.repairStateStatisticsList = repairStateStatisticsList;
    }

    public void fromDomain(RepairTask domain) {
        if (ObjectUtil.isEmptyAll(domain)) {
            return;
        }
        // 项目名称
        this.repairTaskName = domain.getName();
        // 管道名称
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 管段名称
//        this.pipeSegmentName = PipeLineUtil.getPipeSegmentName(domain.getPipeSegmentId());
        // 建议开工时间
        this.planStartDate = StringUtils.convertDateToString(domain.getPlanStartDate(), StringUtils.DATE);
        // 建议竣工时间
        this.planCompletionDate = StringUtils.convertDateToString(domain.getPlanCompletionDate(), StringUtils.DATE);
        // 施工单位
        this.assemblyCompany = domain.getAssemblyCompany();
    }

    public void fromDefectStatistics(List<DefectStatistics> defectStatisticsList) {

        Integer alreadyRepair = 0;
        Integer waitForRepair = 0;
        Integer maintenance = 0;
        Integer difficultToRepair = 0;
        Integer waitForReplace = 0;

        List<DefectInfoStatistics> defectInfoStatisticses = new ArrayList<DefectInfoStatistics>();
        for (DefectStatistics defectStatistics : defectStatisticsList) {
            DefectInfoStatistics defectInfoStatistics = new DefectInfoStatistics();
            defectInfoStatistics.fromDomain(defectStatistics);
            defectInfoStatisticses.add(defectInfoStatistics);
            alreadyRepair += Integer.parseInt(defectStatistics.getAlreadyRepair());
            waitForRepair += Integer.parseInt(defectStatistics.getWaitForRepair());
            maintenance += Integer.parseInt(defectStatistics.getMaintenance());
            difficultToRepair += Integer.parseInt(defectStatistics.getDifficultToRepair());
            waitForReplace += Integer.parseInt(defectStatistics.getWaitForReplace());
        }
        List<RepairStateStatistics> repairStateStatisticses = new ArrayList<RepairStateStatistics>(4);
        repairStateStatisticses.add(new RepairStateStatistics(RepairStateEnum.ALREADY_REPAIR.getLabel(), alreadyRepair));
        repairStateStatisticses.add(new RepairStateStatistics(RepairStateEnum.WAIT_FOR_REPAIR.getLabel(), waitForRepair));
        repairStateStatisticses.add(new RepairStateStatistics(RepairStateEnum.MAINTENANCE.getLabel(), maintenance));
        repairStateStatisticses.add(new RepairStateStatistics(RepairStateEnum.DIFFICULT_TO_REPAIR.getLabel(), difficultToRepair));
        repairStateStatisticses.add(new RepairStateStatistics(RepairStateEnum.WAIT_FOR_REPLACE.getLabel(), waitForReplace));

        this.defectInfoStatisticsList = defectInfoStatisticses;
        this.repairStateStatisticsList = repairStateStatisticses;
    }


    class RepairStateStatistics {

        private String name;
        private Integer val;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getVal() {
            return val;
        }

        public void setVal(Integer val) {
            this.val = val;
        }

        public RepairStateStatistics( String name, Integer val) {
            this.name = name;
            this.val = val;
        }
    }

    /**
     * 缺陷信息统计
     */
    class DefectInfoStatistics {
        // 缺陷类型
        private String featureType;
        // 计划维修个数
        private String planRepair;
        // 已维修个数
        private String alreadyRepair;
        // 待维修个数
        private String waitForRepair;
        // 正在维修个数
        private String maintenance;
        // 难以维修个数
        private String difficultToRepair;
        // 待换管个数
        private String waitForReplace;

        public String getFeatureType() {
            return featureType;
        }

        public void setFeatureType(String featureType) {
            this.featureType = featureType;
        }

        public String getPlanRepair() {
            return planRepair;
        }

        public void setPlanRepair(String planRepair) {
            this.planRepair = planRepair;
        }

        public String getAlreadyRepair() {
            return alreadyRepair;
        }

        public void setAlreadyRepair(String alreadyRepair) {
            this.alreadyRepair = alreadyRepair;
        }

        public String getWaitForRepair() {
            return waitForRepair;
        }

        public void setWaitForRepair(String waitForRepair) {
            this.waitForRepair = waitForRepair;
        }

        public String getMaintenance() {
            return maintenance;
        }

        public void setMaintenance(String maintenance) {
            this.maintenance = maintenance;
        }

        public String getDifficultToRepair() {
            return difficultToRepair;
        }

        public void setDifficultToRepair(String difficultToRepair) {
            this.difficultToRepair = difficultToRepair;
        }

        public String getWaitForReplace() {
            return waitForReplace;
        }

        public void setWaitForReplace(String waitForReplace) {
            this.waitForReplace = waitForReplace;
        }

        public void fromDomain(DefectStatistics domain) {
            // 缺陷类型
            this.featureType = CodeUtil.getName(domain.getFeatureType());
            // 计划维修个数
            this.planRepair = domain.getPlanRepair();
            // 已维修个数
            this.alreadyRepair = domain.getAlreadyRepair();
            // 待维修个数
           this.waitForRepair = domain.getWaitForRepair();
            // 正在维修个数
            this.maintenance = domain.getMaintenance();
            // 难以维修个数
            this.difficultToRepair = domain.getDifficultToRepair();
            // 待换管个数
            this.waitForReplace = domain.getWaitForReplace();
        }
    }
}
